﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using VisaCRM.Modules.Admin.Model;
using VisaCRM.Common.Helper;

namespace VisaCRM.Modules.Admin.Gateway
{
    class DepartmentGateway
    {
        internal ObservableCollection<Department> GetAlldeparments()
        {
            ObservableCollection<Department> allDepartment = new ObservableCollection<Department>();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchDepartmentList());
            if (dt.Rows.Count <= 0)
            {
                return allDepartment;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                allDepartment.Add(new Department()
                {
                    DepartmentID = Convert.ToInt32(dataRow["Department_ID"].ToString()),
                    DepartmentName = dataRow["Department_Name"].ToString(),
                    DepartmentProducts = Convert.ToInt32(dataRow["Department_Products"].ToString()),
                    DepartmentBranchID = Convert.ToInt32(dataRow["Department_BranchID"].ToString())
                });
            }
            return allDepartment;
        }

        internal Department GetCurrentDepartment(int id)
        {
            Department department = new Department();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchCurrentDepartment(id));
            if (dt.Rows.Count <= 0)
            {
                return department;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                department.DepartmentID = Convert.ToInt32(dataRow["Department_ID"].ToString());
                department.DepartmentName = dataRow["Department_Name"].ToString();
            }
            return department;
        }
    }
}
